<?php

namespace App\Http\Middleware;

use Closure;
use App\User;
use App\Permission;
use Illuminate\Support\Facades\Redis;



class auth
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next,$auth)
    {
        if($auth){
            $token = getToken($request);
            $uid =Redis::get("code:".$token);
            //无用户id 返回无权限操作
            if(!$uid)  return ThrowApiExc('42334');

            $user = User::find($uid);
            // if($user->can($auth)){
                return $next($request);
            // }else{
            //     return ThrowApiExc('42334');
            // }

        }else{
            return ThrowApiExc('42334');
        }
    }
}
